﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace DALL.View
{
    public class Exhibition
    {

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public List<Model.View.Exhibition> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FILE_ID,FILE_NAME,TYPE,URLOriginal,URLThumbnail,BRANCH_ID,FILE_FORM,DRESS_TYPE,DRESS_LEVEL,DRESS_COLOR,DRESS_PRICE,WEDDING_COLOR,WEDDING_PRICE,WEDDING_MONTH,WEDDING_STYLE,MATERIAL_STAR,CELEBRATION_TYPE,FILE_TITEL,URLVideoPhoto,MAX_PRICE,MIN_PRICE,REAMRK,AREA,NEWSCHOOL,MYXILAI,HOTEL_NAME,HOTEL_DESK_NUM,HOTEL_STYLE,HOTEL_SPECIFICATION,HOTEL_LOCATION,PROJECT_TYPE,COLOR,STYLE,PROJECTREAMRK,UPDATEUSERNAME,UPDATEUSERID,USERNAME,SETTOPTIME,ISFLAG,USERID,UPTIME ");
            strSql.Append(" FROM Exhibition ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere + "order by SETTOPTIME desc, UPTIME desc");
            }
            List<Model.View.Exhibition> list = new List<Model.View.Exhibition>();
            Database db = DatabaseFactory.CreateDatabase();
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.View.Exhibition ReaderBind(IDataReader dataReader)
        {
            Model.View.Exhibition model = new Model.View.Exhibition();
            object ojb;
            model.FILE_ID = dataReader["FILE_ID"].ToString();
            model.FILE_NAME = dataReader["FILE_NAME"].ToString();
            model.TYPE = dataReader["TYPE"].ToString();
            model.URLOriginal = dataReader["URLOriginal"].ToString();
            model.URLThumbnail = dataReader["URLThumbnail"].ToString();
            ojb = dataReader["BRANCH_ID"];
            if (ojb != DBNull.Value && ojb.ToString() != "")
            {
                model.BRANCH_ID = (int)ojb;
            }
            model.FILE_FORM = dataReader["FILE_FORM"].ToString();
            model.DRESS_TYPE = dataReader["DRESS_TYPE"].ToString();
            model.DRESS_LEVEL = dataReader["DRESS_LEVEL"].ToString();
            model.DRESS_COLOR = dataReader["DRESS_COLOR"].ToString();
            ojb = dataReader["DRESS_PRICE"];

            model.DRESS_PRICE = ojb.ToString();
            
            model.WEDDING_COLOR = dataReader["WEDDING_COLOR"].ToString();
            ojb = dataReader["WEDDING_PRICE"];
           
                model.WEDDING_PRICE = ojb.ToString();
           
            model.WEDDING_MONTH = dataReader["WEDDING_MONTH"].ToString();
            model.WEDDING_STYLE = dataReader["WEDDING_STYLE"].ToString();
            model.MATERIAL_STAR = dataReader["MATERIAL_STAR"].ToString();
            model.CELEBRATION_TYPE = dataReader["CELEBRATION_TYPE"].ToString();
            model.FILE_TITEL = dataReader["FILE_TITEL"].ToString();
            model.URLVideoPhoto = dataReader["URLVideoPhoto"].ToString();
            ojb = dataReader["MAX_PRICE"];
            if (ojb != DBNull.Value && ojb.ToString() != "")
            {
                model.MAX_PRICE = Convert.ToInt32(ojb);
            }
            ojb = dataReader["MIN_PRICE"];
            if (ojb != DBNull.Value && ojb.ToString() != "")
            {
                model.MIN_PRICE = Convert.ToInt32(ojb);
            }
            model.PROJECT_TYPE = dataReader["PROJECT_TYPE"].ToString();
            model.REAMRK = dataReader["REAMRK"].ToString();
            model.AREA = dataReader["AREA"].ToString();
            model.NEWSCHOOL = dataReader["NEWSCHOOL"].ToString();
            model.MYXILAI = dataReader["MYXILAI"].ToString();
            model.HOTEL_NAME = dataReader["HOTEL_NAME"].ToString();
            ojb = dataReader["HOTEL_DESK_NUM"];
           
                model.HOTEL_DESK_NUM = ojb.ToString();
           
            model.HOTEL_STYLE = dataReader["HOTEL_STYLE"].ToString();
            model.HOTEL_SPECIFICATION = dataReader["HOTEL_SPECIFICATION"].ToString();
            model.HOTEL_LOCATION = dataReader["HOTEL_LOCATION"].ToString();
            model.COLOR = dataReader["COLOR"].ToString();
            model.STYLE = dataReader["STYLE"].ToString();
            model.PROJECTREAMRK = dataReader["PROJECTREAMRK"].ToString();
            model.UPDATEUSERNAME = dataReader["UPDATEUSERNAME"].ToString();
            ojb = dataReader["UPDATEUSERID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UPDATEUSERID = (int)ojb;
            }
            model.USERNAME = dataReader["USERNAME"].ToString();
            ojb = dataReader["SETTOPTIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SETTOPTIME = (DateTime)ojb;
            }
            ojb = dataReader["ISFLAG"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ISFLAG = (bool)ojb;
            }
            ojb = dataReader["USERID"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.USERID = (int)ojb;
            }
            ojb = dataReader["UPTIME"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UPTIME = (DateTime)ojb;
            }
            return model;
        }

    }
}
